home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_087 / yaiffr / main.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  157 lines

  1. /*  :ts=8 bk=0
  2.  *
  3.  * main.c:    Driver for the cheesy IFF ILBM reader.
  4.  *
  5.  * Leo L. Schwab            8705.11
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <graphics/gfxbase.h>
  10. #include <graphics/view.h>
  11. #include <stdio.h>
  12. #include <fcntl.h>
  13. #include "myiff.h"
  14.  
  15.  
  16. extern FILE    *fopen();
  17.  
  18.  
  19. struct ViewPort        *vp;
  20. struct View        v, *oldview;
  21. struct GfxBase        *GfxBase;
  22. FILE            *fd;
  23.  
  24. main (ac, av)
  25. char **av;
  26. {
  27.     struct ChunkHeader ch;
  28.  
  29.     openstuff ();        /*  It helps to plug it in...  */
  30.  
  31.     /*
  32.      * Scan all arguments and treat them as files.
  33.      */
  34.     while (++av, --ac) {
  35.         puts (*av);
  36.         if (!(fd = fopen (*av, "r"))) {
  37.             fail ("File open failed.");
  38.             continue;
  39.         }
  40.  
  41.         if (!getchunkheader (fd, &ch)) {
  42.             fail ("Can't discover file type.");
  43.             continue;
  44.         }
  45.         if (ch.TYPE != FORM) {
  46.             fail ("Not an IFF file.");
  47.             continue;
  48.         }
  49.  
  50.         if (!(vp = readform (fd, ch.chunksize))) {
  51.             fail ("readform() failed.");
  52.             continue;
  53.         }
  54.         fclose (fd);  fd = NULL;
  55.  
  56.         puts ("Waiting for you to press RETURN...");
  57.         getchar ();
  58.  
  59.         /*
  60.          * And now we make the views.
  61.          */
  62.         oldview = GfxBase -> ActiView;
  63.  
  64.         InitView (&v);
  65.         v.DxOffset = oldview -> DxOffset;  /* Track     */
  66.         v.DyOffset = oldview -> DyOffset;  /* Preferences */
  67.  
  68.         v.ViewPort = vp;
  69.  
  70.         if (vp -> Modes & LACE)
  71.             v.Modes |= LACE;
  72.  
  73.         centerpict (vp);
  74.  
  75.         MakeVPort (&v, vp);
  76.         MrgCop (&v);
  77.         LoadView (&v);
  78.  
  79.         getchar ();    /*  Wait for next press of RETURN  */
  80.         cleanup ();
  81.     }
  82.  
  83.     closestuff ();
  84. }
  85.  
  86. /*
  87.  * A sleazy hack for overscan images.  If the guy is using 'morerows',
  88.  * then this doesn't quite work.
  89.  */
  90. centerpict (vp)
  91. register struct ViewPort *vp;
  92. {
  93.     if (vp -> Modes & HIRES)
  94.         vp -> DxOffset += (640 - vp->DWidth) / 2;
  95.     else
  96.         vp -> DxOffset += (320 - vp->DWidth) / 2;
  97.  
  98.     if (vp -> Modes & LACE)
  99.         vp -> DyOffset += (400 - vp->DHeight) / 2;
  100.     else
  101.         vp -> DyOffset += (200 - vp->DHeight) / 2;
  102. }
  103.  
  104. openstuff ()
  105. {
  106.     if (!(GfxBase = OpenLibrary ("graphics.library", 0L)))
  107.         die ("Dale is out for the moment.");
  108. }
  109.  
  110. cleanup ()
  111. {
  112.     if (oldview) {
  113.         LoadView (oldview);
  114.         WaitTOF ();
  115.         if (v.LOFCprList) {
  116.             FreeCprList (v.LOFCprList);
  117.             v.LOFCprList = NULL;
  118.         }
  119.         if (v.SHFCprList) {
  120.             FreeCprList (v.SHFCprList);
  121.             v.SHFCprList = NULL;
  122.         }
  123.         oldview = NULL;
  124.     }
  125.  
  126.     if (vp) {
  127.         closeviewport (vp);
  128.         vp = NULL;
  129.     }
  130.     if (fd) {
  131.         fclose (fd);
  132.         fd = NULL;
  133.     }
  134. }
  135.  
  136. closestuff ()
  137. {
  138.     cleanup ();
  139.  
  140.     if (GfxBase)    CloseLibrary (GfxBase);
  141. }
  142.  
  143. fail (str)
  144. char *str;
  145. {
  146.     puts (str);
  147.     cleanup ();
  148. }
  149.  
  150. die (str)
  151. char *str;
  152. {
  153.     puts (str);
  154.     closestuff ();
  155.     exit (20);
  156. }
  157.